<?php
/**
 * Created by PhpStorm.
 * User: chniccs
 * Date: 2019-12-09
 * Time: 10:39
 */

namespace app\app\controller;


use app\constant\WxUserConst;
use app\model\AdminActiveSku;
use app\model\AdminUserVip;
use app\model\AdminVip;
use app\model\AppWxUser;
use app\util\ReturnCode;

class Vip extends Base
{
    /**
     * 获取数据
     */
    public function get()
    {
        $model = AdminVip::get($this->getUserTid(), null, true);
        if (!$model) {
            return $this->buildFailed(ReturnCode::FAILED, '请先配置会员设置');
        }
        $data = $model->getData();

        if ($this->userInfo['type'] == WxUserConst::TYPE_VIP) {
            $userVip = AdminUserVip::get($this->userInfo['uid']);
            if($userVip){
                $data['expiration_time'] = $userVip->expiration_time;
            }else{
                $data['expiration_time'] = '1970-01-01 00:00:00';
            }

        }
        $skus = AdminActiveSku::all(['aid' => $model->goods_id, 'del' => 0]);
        $data['sku'] = $skus;
        $where = ['type' => WxUserConst::TYPE_VIP];
        $where = $this->addTid($where);
        $userVipCount = AppWxUser::where($where)->count('id');
        $data['count'] = $userVipCount;
        $data['userInfo'] = $this->userInfo;
        return $this->buildSuccess($data);
    }

}